<template>
	<view class="search-result">
		<!-- 搜索框 -->
		<view class="search-result-top" :style="'top:' + stickyTop + 'px'">
			<!-- 搜索框 -->
			<u-search searchIconColor="#FF7803" searchIconSize="48" height="80rpx" :showAction="false"
				:clearabled="false" :value="currentValue" @change="changeCurrentValue" @focus="showClearBtn = true"
				@blur="blurClearBtnHidden">
			</u-search>
			<!-- 清除控件 -->
			<view class="clear-btn" @click="clearCurrentValue" v-show="showClearBtn">×</view>
			<text class="text">搜索</text>
		</view>

		<!-- 底部商品 -->
		<view class="search-bottom public345">
			<!-- 左侧列表 -->
			<view class="search-bottom-left">
				<!-- 单个商品 -->
				<view class="one-item">
					<!-- 商品图片 -->
					<view class="one-item-pic">
						<image :src="imagesUrl('search-shopping.png')" mode="widthFix" style="width: 336rpx;" />
					</view>
					<!-- 商品名称 -->
					<view class="one-item-name">
						<text class="pre">预售</text>
						商品名称商品
					</view>

					<!-- 赏别 -->
					<view class="burst-type" :class="{'red':true,'orange':false,'purple':false,'blue':false}">
						竞技一番赏
					</view>

					<!-- 商品价格 -->
					<view class="one-item-price" :class="{'orange':false,'red':true}">
						￥39.63
					</view>
				</view>
				<view class="one-item">
					<view class="one-item-pic">
						<image :src="imagesUrl('search-shopping.png')" mode="widthFix" style="width: 336rpx;" />
					</view>
					<view class="one-item-name">
						商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称
					</view>

					<!-- 赏别 -->
					<view class="burst-type" :class="{'red':false,'orange':true,'purple':false,'blue':false}">
						锁箱一番赏
					</view>

					<view class="one-item-price" :class="{'orange':true,'red':false}">
						￥39.63
					</view>
				</view>
				<view class="one-item">
					<view class="one-item-pic">
						<image :src="imagesUrl('search-shopping.png')" mode="widthFix" style="width: 336rpx;" />
					</view>
					<view class="one-item-name">
						商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称
					</view>

					<!-- 赏别 -->
					<view class="burst-type" :class="{'red':false,'orange':false,'purple':true,'blue':false}">
						爆爆赏
					</view>

					<view class="one-item-price" :class="{'orange':true,'red':false}">
						￥39.63
					</view>
				</view>
			</view>

			<!-- 右侧列表 -->
			<view class="search-bottom-right">
				<view class="one-item">
					<view class="one-item-pic">
						<image :src="imagesUrl('search-shopping.png')" mode="widthFix" style="width: 336rpx;" />
					</view>
					<view class="one-item-name">
						商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称
					</view>

					<!-- 赏别 -->
					<view class="burst-type" :class="{'red':false,'orange':false,'purple':false,'blue':true}">
						商城
					</view>

					<view class="one-item-price" :class="{'orange':false,'red':true}">
						￥39.63
					</view>
				</view>
				<view class="one-item">
					<view class="one-item-pic">
						<image :src="imagesUrl('search-shopping.png')" mode="widthFix" style="width: 336rpx;" />
					</view>
					<view class="one-item-name">
						商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称
					</view>
					<view class="one-item-price" :class="{'orange':false,'red':true}">
						￥39.63
					</view>
				</view>
				<view class="one-item">
					<view class="one-item-pic">
						<image :src="imagesUrl('search-shopping.png')" mode="widthFix" style="width: 336rpx;" />
					</view>
					<view class="one-item-name">
						商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称
					</view>
					<view class="one-item-price" :class="{'orange':false,'red':true}">
						￥39.63
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 吸顶
				stickyTop: 0,

				showClearBtn: false,

				currentValue: '',

			}
		},
		onLoad(option) {
			// 接收搜索页面传递的参数
			this.currentValue = option.value
		},
		methods: {
			clickOneTab(item) {
				console.log('item', item);
			},
			changeCurrentValue(value) {
				this.currentValue = value
			},
			// 失去焦点 定时器隐藏清除控件
			blurClearBtnHidden() {
				setTimeout(() => {
					this.showClearBtn = false
				}, 100)
			},
			// 清除当前值
			clearCurrentValue() {
				this.currentValue = ''
			}
		},
		watch: {
			// 监听当前input的值
			currentValue(newValue, oldValue) {
				if (newValue === '') {
					// 值为空 跳转到搜索页
					uni.navigateTo({
						url: '/pages/search/search'
					})
				}
			}
		},
		mounted() {
			this.stickyTop = uni.getSystemInfoSync().windowTop
		}
	}
</script>

<style lang="scss" scoped>
	.search-result {

		// 顶部搜索框
		.search-result-top {
			position: sticky;
			display: flex;
			padding: 16rpx 30rpx;
			background: #fff;
			
			/* #ifdef APP-PLUS */
			z-index: 9;
			/* #endif */

			// 搜索框清除控件
			.clear-btn {
				position: absolute;
				top: 50%;
				left: 556rpx;
				width: 32rpx;
				height: 32rpx;
				border-radius: 50%;
				background: #D8D8D8;
				color: #fff;
				font-size: 32rpx;
				text-align: center;
				line-height: 30rpx;
				transform: translateY(-50%);
				z-index: 99;
			}

			.text {
				margin: 26rpx 0 26rpx 30rpx;
				font-size: 32rpx;
				line-height: 28rpx;
				color: #FF7803;
			}
		}

		.search-bottom {
			display: flex;
			padding-top: 18rpx;

			.search-bottom-left {
				margin-right: 18rpx;
			}

			.one-item {
				background-color: #fff;
				margin-bottom: 18rpx;
				border-radius: 16rpx;
				overflow: hidden;

				.one-item-name {
					margin: 24rpx 16rpx;
					font-size: 28rpx;
					color: #333;
					line-height: 32rpx;
					// 溢出隐藏
					-webkit-line-clamp: 2;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					overflow: hidden;
					text-overflow: ellipsis;

					// 预售
					.pre {
						display: inline-block;
						width: 44rpx;
						height: 32rpx;
						border-radius: 8rpx;
						background: rgba(234, 110, 122, 0.2);
						margin-right: 10rpx;
						font-size: 18rpx;
						color: #F51F43;
						text-align: center;
						line-height: 32rpx;
					}
				}

				// 赏别
				.burst-type {
					display: inline-block;
					padding: 4rpx 8rpx;
					margin-left: 16rpx;
					font-size: 18rpx;
					font-weight: 500;
					color: #fff;

					border-radius: 4rpx;

					&.orange {
						background: #FF7803;
					}

					&.red {
						background: #FE245E;
					}

					&.purple {
						background: #9932FD;
					}

					&.blue {
						background: #198EF9;
					}
				}

				.one-item-price {
					padding: 14rpx 0 24rpx 16rpx;
					font-size: 32rpx;
					line-height: 32rpx;
					font-weight: 500;

					&.orange {
						color: #FF7803;
					}

					&.red {
						color: #F51F43;
					}
				}
			}
		}
	}
</style>
